package org.book.controller;

import com.alibaba.fastjson.JSON;
import org.book.interceptor.LoginInterceptor;
import org.book.model.User;
import org.book.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户controller
 * Created by weican on 2017/7/14.
 */
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {
    private static Logger log = LoggerFactory.getLogger(LoginInterceptor.class);

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/{userName}", method = RequestMethod.GET)
    public String getUserByUserName(@PathVariable("userName") String userName) {
        log.info("userName === " + userName);
        User user = userService.getUserByUserName(userName);
        return JSON.toJSONString(user);
    }
}
